/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.gui.table;

import com.camachosanchez.util.Constantes;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Rolando
 */
public class RenderizadorTablaRecepcionMarcado implements TableCellRenderer {

    TableCellRenderer tcr;

    public RenderizadorTablaRecepcionMarcado(TableCellRenderer tcr) {
        this.tcr = tcr;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        table.getTableHeader().setOpaque(false);
        JComponent wth = (JComponent) tcr.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        JLabel label = (JLabel) wth;
        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

//        JTableHeader header = table.getTableHeader();
//        header.setBackground(Color.RED);
//        header.setFont(new Font("Tahoma", Font.PLAIN, 12));

        if (value instanceof String) {
            JLabel etiqueta = new JLabel();
            etiqueta.setOpaque(true);
            if (value == null) {
                etiqueta.setText("");
            } else {
                String texto = (String) ("" + value);
                etiqueta.setText(texto.toUpperCase());
                etiqueta.setFont(new Font("Tahoma", Font.PLAIN, 12));
            }
//            if (row % 2 == 0) {
//                etiqueta.setBackground(Constantes.TABLA);
//            } else {
            etiqueta.setBackground(Color.white);
//            }
            if (column < 4) {
                etiqueta.setHorizontalAlignment(JLabel.CENTER);
            }
            if (column == 7) {
                etiqueta.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                if (value != null && ("" + value).compareTo("") != 0) {
                    etiqueta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/observacion_entrada.png")));
                }
//                etiqueta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/observacion.png")));
                etiqueta.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 1));
            }
            return etiqueta;
        } else {
            JCheckBox check = new JCheckBox();
            check.setHorizontalAlignment(JLabel.CENTER);
            if (row % 2 == 0) {
                check.setForeground(table.getSelectionForeground());
//                check.setBackground(Constantes.TABLA);
            } else {
                check.setForeground(table.getForeground());
            }
            check.setBackground(Color.white);
            check.setSelected((value != null && ((Boolean) value).booleanValue()));
            JTableHeader header = table.getTableHeader();
            header.setBackground(Constantes.CABECERA);
            header.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
            return check;
        }
    }
}
